//
//  TPViewController+TPNavBarExtension.m
//  Pods
//
//  Created by caixun on 15/11/6.
//
//

#import "TPViewController+TPNavBarExtension.h"
#import "TPNavigationBarView.h"


@implementation TPViewController (TPNavBarExtension)


#pragma mark - ************************************** 创建导航栏 *************************************

/// 根据标题创建导航栏
- (void)createNavBarViewWithTitle:(id)idTitle
{
    if (!self.superNavBarView)
    {
        /// 创建导航栏
        self.superNavBarView = [[TPNavigationBarView alloc] initWithTitle:@""];
        [self.view addSubview:self.superNavBarView];
    }
    
    /// 设置中间标题
    [self.superNavBarView setIdNavTitle:idTitle];
}

/// 创建左侧返回按钮
- (void)createNavLeftBtnWithItem:(id)idItem target:(id)target action:(SEL)selAction
{
    if (!self.superNavBarView)
    {
        /// 创建导航栏
        self.superNavBarView = [[TPNavigationBarView alloc] initWithTitle:@""];
        [self.view addSubview:self.superNavBarView];
    }
    
    if (idItem)
    {
        [self.superNavBarView createNavLeftBtnWithItem:idItem];
        [self.superNavBarView.btnLeft addTarget:target
                                         action:selAction
                               forControlEvents:UIControlEventTouchUpInside];
    }
}

/// 创建右侧按钮
- (void)createNavRightBtnWithItem:(id)idItem target:(id)target action:(SEL)selAction
{
    if (!self.superNavBarView)
    {
        /// 创建导航栏
        self.superNavBarView = [[TPNavigationBarView alloc] initWithTitle:@""];
        [self.view addSubview:self.superNavBarView];
    }
    
    if (idItem)
    {
        [self.superNavBarView createNavRightBtnWithItem:idItem];
        [self.superNavBarView.btnRight addTarget:target
                                          action:selAction
                                forControlEvents:UIControlEventTouchUpInside];
    }
}


@end
